﻿using MMITDomain.Concrete;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using MMITDomain.Entities;
using Moq;
using System.Collections.Generic;
using System.Linq;

namespace MMITUnitTests
{
    /// <summary>
    ///This is a test class for EFCountryRepositoryTest and is intended
    ///to contain all EFCountryRepositoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class EFCountryRepositoryTest
    {
        private TestContext testContextInstance;
        EFCountryRepository MockCountryRepository;
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion
        [TestInitialize]
        public void Initialize()
        {
            var target = new Mock<EFCountryRepository>();
            var countries = new List<Country> { new Country{ Name="Nigeria", Id=1, ISOCode="NGN", Currencies = new List<Currency>{}},
                new Country{ Name="United States Of America", Id=2, ISOCode="USD", Currencies = new List<Currency>{}},
                new Country{ Name="United Kingdom", Id=3, ISOCode="GBP", Currencies = new List<Currency>{}},
                new Country{ Name="France", Id=4, ISOCode="FR", Currencies = new List<Currency>{}},
            }.AsQueryable();

            target.Setup(p => p.Countries).Returns(countries);
            target.Setup(p => p.GetCountryById(It.IsAny<int>())).Returns((int countryId) => countries.Where(o => o.Id == countryId).Single());

            MockCountryRepository = target.Object;
        }
        /// <summary>
        ///A test for GetDefaultCurrency
        ///</summary>
        [TestMethod()]
        public void GetDefaultCurrencyTest()
        {
            throw new NotImplementedException();
        }

        [TestMethod()]
        public void CanSaveCountry()
        {
            throw new NotImplementedException();
        }

        [TestMethod()]
        public void CanDeleteCountry()
        {
            throw new NotImplementedException();
        }

        [TestMethod()]
        public void CanGetCountryById()
        {
            //Arrange
            int countryId = 2;
            //Act
            var actual = MockCountryRepository.GetCountryById(countryId);
            //Assert
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(Country));
            Assert.AreEqual("United States Of America", actual.Name);
        }

        [TestMethod()]
        public void CanGetAllCountries()
        {
            throw new NotImplementedException();
        }
    }
}
